# $Id: PKGBUILD 141113 2011-10-24 09:59:23Z dreisner $
# Maintainer: Tom Gundersen <teg@jklm.no>
# Contributor: Aaron Griffin <aaron@archlinux.org>
# Contributor: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: Thomas Bächler <thomas@archlinux.org>

# ALARM: Jason Plum <max@warheads.net>
#  - Make this compatible with non-accept4 kernels.
#  - due to newer udev requiring devtmpfs (not available in .31), keeping udev at 175

plugrel=1

_pkgbase='udev'
pkgname='udev-oxnas'
pkgver=182
_pkgver=175
pkgrel=2
arch=(i686 x86_64)
url="http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html"
license=('GPL')
options=(!makeflags !libtool)
makedepends=('gobject-introspection' 'gperf')
source=(http://www.kernel.org/pub/linux/utils/kernel/hotplug/$_pkgbase-$_pkgver.tar.bz2
        81-arch.rules
        pre-accept4-kernel.patch)
md5sums=('2fc9c1efcbde98e3d73ffee7a77aea47'
         '3da2bb9891592f9438a07bd641465531'
         '8b28d85b2158be1b5a190135c9cc8851')

build() {
  cd $srcdir/$_pkgbase-$_pkgver

  patch -Np1 -i ${srcdir}/pre-accept4-kernel.patch
  ./configure --sysconfdir=/etc\
              --with-rootlibdir=/lib\
              --libexecdir=/lib/udev\
              --sbindir=/sbin\
              --with-systemdsystemunitdir=/lib/systemd/system\
              --disable-rule-generator\
              --enable-udev_acl

  make
}
  
package_udev-oxnas() {
  pkgdesc="The userspace dev tools for old kernels (udev ${_pkgver})"
  depends=('util-linux' 'libusb-compat' 'glib2' 'kmod' 'pciutils')
  install=udev.install
  backup=(etc/udev/udev.conf)
  provides=("udev=${pkgver}")
  conflicts=('udev')
  
  cd $srcdir/$_pkgbase-$_pkgver
  make DESTDIR=${pkgdir} install
  # Install our rule for permissions and symlinks
  install -D -m644 $srcdir/81-arch.rules $pkgdir/lib/udev/rules.d/81-arch.rules

  # create framebuffer blacklist
  mkdir -p $pkgdir/lib/modprobe.d/
  for mod in $(find /lib/modules/*/kernel/drivers/video -name '*fb.ko.gz' -exec basename {} .ko.gz \;); do 
  	echo "blacklist $mod" 
  done | sort -u > $pkgdir/lib/modprobe.d/framebuffer_blacklist.conf

  # /dev/loop0 is created for convenience, to autoload the module if necessary
  # may be obsoleted by https://lkml.org/lkml/2011/7/30/111
  mknod -m 0660 ${pkgdir}/lib/udev/devices/loop0 b 7 0
  chgrp disk ${pkgdir}/lib/udev/devices/loop0

  # udevd moved, symlink to make life easy for restarting udevd manually
  ln -s /lib/udev/udevd ${pkgdir}/sbin/udevd

  # Replace dialout/tape/cdrom group in rules with uucp/storage/optical group
  for i in $pkgdir/lib/udev/rules.d/*.rules; do
    sed -i -e 's#GROUP="dialout"#GROUP="uucp"#g;
               s#GROUP="tape"#GROUP="storage"#g;
               s#GROUP="cdrom"#GROUP="optical"#g' $i
  done
}
